<%@page import="com.wowangz.cms.common.utils.DictTypeConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<c:set value="<%=SysConstant.CommonApproveStatus.SAVED %>" var="state"></c:set>
<c:set value="<%=SysConstant.CommonApproveStatus.REFUSED %>" var="refuse"></c:set>
<script type="text/javascript">
	$(document).ready(function() {
		/* var width = document.body.clientWidth;
		$("#description").css("width",width*0.68+"px"); */
		$("#quality").selectutil({
			optModel : <%=DictTypeConstant.getDataDictionaryInfoSelectList(DictTypeConstant.QUALITY,false,false)%>,
			optDefault :'${store.quality}'
		});
		$("#industry").selectutil({
			optModel : <%=DictTypeConstant.getDataDictionaryInfoSelectList(DictTypeConstant.STOREINDUSTRY,false,false)%>,
			optDefault :'${store.industry}'
		});
		$("#population").selectutil({
			optModel : <%=DictTypeConstant.getDataDictionaryInfoSelectList(DictTypeConstant.POPULATION,false,false)%>,
			optDefault :'${store.population}'
		});
		$("#butReturn").click(function(){
			parent.document.location.reload();
		    $.fn.closeIssWindow();
		});
		selectCityByProvinceId();
	});
	
	/*flag == 1 表示保存，flag == 2 表示提交*/
	function save(flag){
		var exp = $('#form1').validationEngine('validate');
		var description = $("#description").val();
		if(description.length > 1000){
			alert('<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.description.length")%>');
			return ;
		}
		if(exp==true){
			// 显示进度条
			showSending();
			$.ajax({
				type: 'POST',
			    url: '${systemctx}/dailyoperation/store/save.web?flag='+flag,
			    data: $("#form1").serialize(),
			    dataType: 'json',
			    success: function(data) {
			    	//关闭执行...
					closeSending();
			    	if(data.code == 200){
			    		parent.document.location.reload();
					    $.fn.closeIssWindow();
			    	}else {
			    		messageAlert(data.message);
			    	}
			    }
			});
		}
	}
	
	function selectCityByProvinceId() {
		var provinceid = $("#provinceid").val();
		var value = '<%=MessageResourcesUtils.getMessage(request, "common.select.all")%>';
		var str = '<option value="">'+value+'</option>';
		if(provinceid != "" && provinceid != undefined){
			$.getJSON('${systemctx}/dailyoperation/store/getCityJson.json?id='+provinceid,function(data){
				for(var i = 0;i < data.length; i++){
					if(data[i].id=='${store.cityid}'){
						str += "<option value=\""+data[i].id+"\" selected=\"selected\">"+data[i].cityname+"</option>";
					}else {
						str += "<option value=\""+data[i].id+"\">"+data[i].cityname+"</option>";
					}
				}
				$("#cityid").html(str);
			});
		}
	}
</script>
<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "store.manage.title")%>
			<span></span>
			<c:if test="${store.id != '' && store.id != null && not empty store.id}">
				<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.edit") %>
			</c:if>
			<c:if test="${empty store.id}">
				<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.add") %>
			</c:if>
			
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.register.info") %>
						</label>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.number") %>
						</label>
						<input type="hidden" value="${store.id}" id="id" name="id" />		
						<input type="hidden" value="${number}" id="number" name="number" />		
						<span><input type="text" value="${number}" disabled="disabled" size="22" class="validate[required,maxSize[20]]" /></span>
					</li>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name") %>
						</label>
						<span><input type="text" id="name" value="${store.name}" name="name" maxlength="100" size="100" class="validate[required,maxSize[100]]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.corporate") %>
						</label>
						<span><input type="text" id="corporate" value="${store.corporate}" name="corporate" maxlength="100" size="100" class="validate[required,maxSize[100]]" /></span>		
					</li>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.quality") %>
						</label>
						<span><select name="quality" id="quality" class="validate[required]"></select></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.population") %>
						</label>
						<span><select id="population" name="population" class="validate[required]"></select></span>		
					</li>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.pCity") %>
						</label>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.provinceid") %>
						</label> 
						<select id="provinceid" name="provinceid" onchange="selectCityByProvinceId()" style="width:120px;" class="validate[required]">
							<option value="">省市/自治区</option>
							<c:forEach items="${provinces}" var="p">
								<option value="${p.id}" <c:if test="${p.id==store.provinceid}">selected="selected"</c:if> >${p.provincename}</option>
							</c:forEach>
						</select>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.cityid") %>
						</label>
						<select id="cityid" name="cityid" style="width:120px;" class="validate[required]">
							<option value="">市/区</option>
						</select>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.industry") %>
						</label>
						<span><select id="industry" name="industry"></select></span>
					</li>
				</ul>
				<ul>
					<li style="height:80px;width: 100%">
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.description") %>
						</label>
						<span><textarea rows="" cols="" class="validate[maxSize[1000]]" maxlength="1000" id="description" name="description" style="width:600px;height:80px;">${store.description}</textarea></span>
						
					</li>
				</ul>
				<ul>
					<li>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.contacts.info") %>
						</label>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.realname") %>
						</label>
						<span><input type="text" id="realname" name="realname" value="${store.realname}" maxlength="20" size="20" class="validate[required]" /></span>		
					</li>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.telephonenumber") %>
						</label>
						<span><input type="text" id="telephonenumber"  size="20" maxlength="20" value="${store.telephonenumber}" name="telephonenumber" maxlength="22" size="22" class="validate[required,custom[phone]]" /></span>		
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.email") %>
						</label>
						<span><input type="text" id="email" name="email" value="${store.email}" maxlength="30" size="30" class="validate[required,custom[email]]" /></span>		
					</li>
					<li>
						<i></i> 
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.phonenumber") %>
						</label>
						<span><input type="text" id="phonenumber" value="${store.phonenumber}" name="phonenumber" maxlength="22" size="22" class="" /></span>		
					</li>
				</ul>
			</div>
			<div class="button-group">
				<input type="button" class="btn btn-default" onclick="save('1')" id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
				<input type="button" class="btn btn-default" onclick="save('2')" id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.submit") %>' />
				<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>